# vim:set noet ts=4:
#
# scim-python
#
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA
#
# $Id: $
#

# if not 1, append svn revision to the version number.
m4_define([scim_python_released], [1])
m4_define([scim_python_major_version], [0])
m4_define([scim_python_minor_version], [1])
m4_define([scim_python_micro_version], [13rc1])
m4_define([scim_python_maybe_revision],
          m4_esyscmd([if test x]scim_python_released[ != x1; then echo -n .svn`svn info . --xml|grep revision | sed "s/ *revision=\"\([0-9]*\)\">/\1/g"|head -n 1`; fi]))

m4_define([scim_python_version],
          scim_python_major_version.scim_python_minor_version.scim_python_micro_version[]scim_python_maybe_revision)

AC_INIT([scim-python], [scim_python_version], [http://code.google.com/p/scim-python/issues/entry],[scim-python])
  
AM_INIT_AUTOMAKE([1.9])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_GNU_SOURCE

# define PACKAGE_VERSION_* variables
AS_VERSION
AS_NANO

AM_SANITY_CHECK
AM_MAINTAINER_MODE
AM_DISABLE_STATIC
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_ISC_POSIX
AC_HEADER_STDC
AM_PROG_LIBTOOL
AM_PATH_GLIB_2_0
AM_PATH_PYTHON([2.5])

AC_PROG_LIBTOOL


# check gtk & pygtk
PKG_CHECK_MODULES(GTK2, [
	gtk+-2.0
])

PKG_CHECK_MODULES(PYGTK2, [
	pygtk-2.0
])


# define PYTHOPN_CFLAGS & PYTHON_LIBS
PYTHON_CONFIG=`type -p python$PYTHON_VERSION-config`
if test "$PYTHON_CONFIG" != ""; then
	PYTHON_CFLAGS=`$PYTHON_CONFIG --includes`
	PYTHON_LIBS=`$PYTHON_CONFIG --libs`
else
	PYTHON_CFLAGS=`$PYTHON $srcdir/python-config.py --includes`
	PYTHON_LIBS=`$PYTHON $srcdir/python-config.py --libs`
fi

AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_LIBS)

# setup debian dpkg
AC_ARG_ENABLE([debian-dpkg],
	[AC_HELP_STRING([--enable-debian-dpkg], 
		[enale build dpkg for Debian or Ubuntu Linux.]
		)
	]
)

if test "$enable_debian_dpkg" != "yes"; then
	AM_CONDITIONAL(ENABLE_DEBIAN_DPKG, [false])
else
	AM_CONDITIONAL(ENABLE_DEBIAN_DPKG, [true])
fi

# check python-enchant
AC_MSG_CHECKING([for python-enchant])
if ! $PYTHON -c "import enchant" 2>/dev/null; then
	AC_MSG_RESULT([no])
	have_python_enchant=no
else
	AC_MSG_RESULT([yes])
	have_python_enchant=yes
fi

AC_ARG_ENABLE([english-writer],
	[AC_HELP_STRING([--disable-english-writer], 
		[Don't build and install EnglishWirter Engine & SetupUI]
		)
	]
)

if test "$enable_english_writer" == "force"; then
	AM_CONDITIONAL(ENABLE_ENGLISH_WRITER, [true])
elif test "$enable_english_writer" == "no"; then
	AM_CONDITIONAL(ENABLE_ENGLISH_WRITER, [false])
else
	if test "$have_python_enchant" == "no"; then
		AC_MSG_ERROR([
		Your system does not have python-enchant, please install it or run "./configure --disable-english-writer".
		You may also use "./configure --enable-english-writer=force" to foce build this english engine.])
	else
		AM_CONDITIONAL(ENABLE_ENGLISH_WRITER, [true])
	fi
fi

# setup PinYin option
AC_ARG_ENABLE([pinyin],
	[AC_HELP_STRING([--disable-pinyin], 
		[Don't build and install PinYin]
		)
	]
)

if test "$enable_pinyin" != "no"; then
	AM_CONDITIONAL(ENABLE_PINYIN, [true])
else
	AM_CONDITIONAL(ENABLE_PINYIN, [false])
fi

# setup XingMa option
AC_ARG_ENABLE([xingma],
	[AC_HELP_STRING([--disable-xingma],
		[Don't build and install XingMa]
		)
	]
)

if test "$enable_xingma" != "no"; then
	AM_CONDITIONAL(ENABLE_XINGMA, [true])
else
	AM_CONDITIONAL(ENABLE_XINGMA, [false])
fi


# check scim and define SCIM_* variables
PKG_CHECK_MODULES(SCIM, [
	scim >= 1.4
])
SCIM_BIN_VER=`$PKG_CONFIG --variable=scim_binary_version scim`

if test "$SCIM_BIN_VER" = ""; then
	SCIM_BIN_VER=1.4.0
fi

if test "$SCIM_ICONDIR" = ""; then
	SCIM_ICONDIR=${datadir}/scim/icons
fi

if test "$SCIM_MODULEDIR" = ""; then
	SCIM_MODULEDIR=${libdir}/scim-1.0/$SCIM_BIN_VER
fi

if test "$SCIM_DATADIR" = ""; then
	SCIM_DATADIR=${datadir}/scim
fi

AC_SUBST(SCIM_ICONDIR)
AC_SUBST(SCIM_MODULEDIR)
AC_SUBST(SCIM_DATADIR)
AC_SUBST(SCIM_BIN_VER)

# define GETTEXT_* variables
GETTEXT_PACKAGE=scim-python
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Package name for gettext])

AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.16.1)

# OUTPUT files
AC_CONFIG_FILES([ po/Makefile.in
Makefile
scim-python.spec
src/Makefile
src/scim.pth
data/Makefile
data/icons/Makefile
python/Makefile
python/scim/Makefile
python/engine/Makefile
python/engine/EnglishWriter/Makefile
python/engine/PinYin/Makefile
python/engine/XingMa/Makefile
python/engine/XingMa/tables/Makefile
python/setupui/Makefile
python/setupui/EnglishWriter/Makefile
python/helper/Makefile
python/helper/PinYinSetup/Makefile
python/helper/ZhengJuSetup/Makefile
m4/Makefile
])

AC_OUTPUT
